package fun.easycode.webterminal.adapter.api;

import fun.easycode.webterminal.common.contract.PageDTO;
import fun.easycode.webterminal.common.contract.R;
import fun.easycode.webterminal.service.MachineTunnelService;
import fun.easycode.webterminal.service.cmd.MachineTunnelPageQry;
import fun.easycode.webterminal.service.cmd.MachineTunnelSaveCmd;
import fun.easycode.webterminal.service.dto.MachineTunnelDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

@Tag(name = "隧道")
@RestController
@RequestMapping("/api/machine-tunnel")
public class MachineTunnelApi {

    private final MachineTunnelService machineTunnelService;

    public MachineTunnelApi(MachineTunnelService machineTunnelService) {
        this.machineTunnelService = machineTunnelService;
    }

    @PostMapping("/delete")
    @Operation(summary = "删除隧道")
    public R<String> delete(@RequestParam String id) {
        return machineTunnelService.delete(id);
    }

    @GetMapping("/get-by-id")
    @Operation(summary = "根据id查询隧道")
    public R<MachineTunnelDTO> getById(@RequestParam String id){
        return machineTunnelService.getById(id);
    }

    @GetMapping(value = "/page")
    @Operation(summary = "分页查询隧道")
    public R<PageDTO<MachineTunnelDTO>> page(@ParameterObject MachineTunnelPageQry cmd) {
        return machineTunnelService.page(cmd);
    }

    @PostMapping("/save")
    @Operation(summary = "保存隧道(新建/编辑)")
    public R<String> save(@RequestBody MachineTunnelSaveCmd cmd) {
        return machineTunnelService.save(cmd);
    }

    @PostMapping("/start")
    @Operation(summary = "启动隧道")
    public R<String> start(@RequestParam String id) {
        return machineTunnelService.start(id);
    }

    @PostMapping("/stop")
    @Operation(summary = "停止隧道")
    public R<String> stop(@RequestParam String id) {
        return machineTunnelService.stop(id);
    }
}
